﻿#pragma once
#pragma execution_character_set("utf-8")
// 本文件为utf-8 编码格式

#ifndef __GD__GDImageView__
#define __GD__GDImageView__

#include "CrossApp.h"
#include "../util/GDHttpUtil.h"

class GDImageView :
	public CAView
	, public CommonUrlImageViewDelegate
{

public:
	static GDImageView* createWithFrame(const CCRect& rect, CAImage *defaultImage = CAImage::CC_WHITE_IMAGE(), const HttpGetImageType& type = HttpGetImageDefault);
	static GDImageView* createWithFrame(const CCRect& rect, const CAColor4B& color4B, CAImage *defaultImage = CAImage::CC_WHITE_IMAGE(), const HttpGetImageType& type = HttpGetImageDefault);
	static GDImageView* createWithCenter(const CCRect& rect, CAImage *defaultImage = CAImage::CC_WHITE_IMAGE(), const HttpGetImageType& type = HttpGetImageDefault);
	static GDImageView* createWithCenter(const CCRect& rect, const CAColor4B& color4B, CAImage *defaultImage = CAImage::CC_WHITE_IMAGE(), const HttpGetImageType& type = HttpGetImageDefault);

	virtual ~GDImageView();

	bool init();

	CC_SYNTHESIZE(CommonUrlImageViewDelegate*, m_pDelegate, Delegate);
	void imageViewRequestFinished(CommonUrlImageView* imageView);
	CC_SYNTHESIZE_PASS_BY_REF(CAImageViewScaleType, m_eImageViewScaleType, ImageViewScaleType);

	// 设置默认图片
	void setColor(const CAColor4B& color);
	void setFrame(const CCRect &rect);
	void setDefaultImage(CAImage *image, bool isResetImageRect=false);
	void setImageUrl(const std::string& url);
	std::string getUrl();
	void setUrl(const std::string& url);
	/* 重置图片位置 */
	void resetImageRect();
	// 测试显示提示内容用
	void setTipLabel(CALabel *tipLabel);
	CommonUrlImageView* getCommonUrlImageView();
	bool isImageRequestFinished();
	bool getIsSetUrl();
    
    virtual void setSuperview(CAView* superview);
protected:
    
    CC_SYNTHESIZE_READONLY(bool, isLoad, IsLoad);
    
private:
	GDImageView();
	void initView(CAImage *defaultImage = CAImage::CC_WHITE_IMAGE(), const HttpGetImageType& type = HttpGetImageDefault);
	void resetImageRectXY();
	void resetImageRectCrop();
	void resetImageRectInside();
	
private:
	CommonUrlImageView *image;
	CALabel *tipLabel;
	bool isAddImage;
	bool isImageViewRequestFinished;
	bool isSetUrl;
    std::string i_url;
};
#endif /* defined(__GD__GDImageView__) */